using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MoGameLib
{
    public class Map
    {
        Tile[,] m_Tiles;

        protected int m_Width;
        protected int m_Height;

        public int Width
        {
            get { return m_Width; }
        }

        public int Height
        {
            get { return m_Height; }
        }

        public int MaxCellX
        {
            get { return m_Width - 1; }
        }

        public int MaxCellY
        {
            get { return m_Height - 1; }
        }

        public Tile GetTile(int x, int y)
        {
            return m_Tiles[x, y];
        }

        protected Board m_Board;

        public Board Board
        {
            get { return m_Board; }
            set { m_Board = value; }
        }

        public Map()
        {
            m_Board = new Board(this);
        }

        public void Load(string fileName)
        {
            StreamReader file = new StreamReader(fileName);
            List<string> lines = new List<string>();
            string line;
            while ((line = file.ReadLine()) != null)
            {
                lines.Add(line);
            }

            if (lines.Count > 0)
            {
                m_Width = lines[0].Length;
                m_Height = lines.Count;
                m_Tiles = new Tile[m_Width, m_Height];

                int x = 0, y = 0;

                foreach (string l in lines)
                {
                    x = 0;

                    foreach (char c in l.ToCharArray())
                    {
                        m_Tiles[x, y] = new Tile();
                        m_Tiles[x, y].Terrain = MoCore.World.Terrains.GetTerrain(c.ToString());
                        x++;
                    }
                    y++;
                }

            }
        }


    }
}
